import Collection from 'ol/Collection'
import TyFeatureLayer from './TyFeatureLayer'
import Modify from 'ol/interaction/Modify'
import {click, shiftKeyOnly, singleClick} from 'ol/events/condition'
import TyCoordinateConvert from './TyCoordinateConvert'
import {Circle as CircleStyle, Fill, Stroke, Style, Text} from 'ol/style'
import TyDrawTool from './TyDrawTool'
import Select from 'ol/interaction/Select'
import {MultiPolygon, Polygon} from 'ol/geom'
import Feature from 'ol/Feature'

class TyDrawPolygon {
  constructor(option) {
    this.map = option.map
    this.drawTool = null
    // 所有待分割多边形
    this.aoFeatures = option.aoFeatures ? option.aoFeatures : []
    // 所有待分割多边形部分区域
    this.aoFocusOn = option.aoFocusOn ? option.aoFocusOn : []
    // 是否是WGS84经纬度坐标
    this.isWGS84 = option.isWGS84 ? option.isWGS84 : false
    // 编辑对象
    this.modify = null
    // 指定参与编辑features的对象
    this.Collection = new Collection()
    // 判断是否存在被切割，即判断切割线是否与多边形有交点
    this.isHasIn = false
    // 切割后的多边形
    this.aoCreatePolygon = []
    // 需要删除的对象，为分割前的多边形
    this.aoDeletePolygon = []
    // selecl对象
    this.selectClick = null
    // 构建撤销功能
    this.aoLastStep = []
    this.stepIndex = 1
    // 当前选中要素
    this.selectedFeature = null
    this.selectedFeatures = []
    // 是否开启合并
    this.isMergePolygon = false
    // 绘制管理图层
    this.isMultiSelect = false
    this.multiSelectPolygon = []
    this.featureGroup = new TyFeatureLayer({ map: this.map })
    // 初始化样式以及绘制工具，选择工具
    this.initTool()
    // 初始化参与分割的多边形
    this.initFocusFeatures()
  }

  deleteFocusFeature(feature) {
    for (let i = 0; i < this.aoFocusOn.length; i++) {
      if (this.aoFocusOn[i] === feature) {
        this.aoFocusOn.splice(i, 1)
        return
      }
    }
    this.aoFeatures = this.aoFocusOn
  }
  // 清空图层
  clear() {
    this.deleteFeature(true)
    this.featureGroup.clear()
    this.initFeatures()
  }

  // 获取上一次切割数据
  lastStep() {
    this.stepIndex = this.aoLastStep.length
    if (this.stepIndex > 0) {
      this.changeFeature()
    } else {
      alert('已经是最初始状态！')
    }
  }
  changeFeature() {
    const lastFeature = this.aoLastStep[this.stepIndex - 1]
    for (let j = 0; j < lastFeature[0].length; j++) {
      this.featureGroup.addFeature(lastFeature[0][j])
      this.aoFocusOn.push(lastFeature[0][j])
    }
    for (let i = 0; i < lastFeature[1].length; i++) {
      this.featureGroup.removeFeature(lastFeature[1][i])
      for (let k = this.aoFocusOn.length; k >= 0; k--) {
        if (this.aoFocusOn[k] === lastFeature[1][i]) {
          this.aoFocusOn.splice(k, 1)
        }
      }
    }
    this.aoLastStep.splice(this.stepIndex - 1, 1)
    this.stepIndex--
    if (this.stepIndex === 0) {
      this.aoFocusOn = [].concat(lastFeature[0])
    }
    this.aoFeatures = this.aoFocusOn
  }
  // 清空图层初始化对象
  initFeatures() {
    // 切割后的多边形
    this.aoCreatePolygon = []
    // 需要删除的对象，为分割前的多边形
    this.aoDeletePolygon = []
    this.multiSelectPolygon = []
    // 所有待分割多边形
    this.aoFeatures = []
    // 所有待分割多边形部分区域
    this.aoFocusOn = []
  }
  // ++++++++++++++增加简单编辑的功能+++++++++++++++++++++++++
  openEdit() {
    // console.log(this.map);
    // 当需要被编辑的多边形数为0的时候
    const features = this.aoFocusOn
    // console.log(features);
    // if (features.length == 0 ) {
    //    this.map.fire("removeModify", {});
    //    this.map.un("removeModify", this.removeModify, this);
    //    return;
    // }
    // 加入需要编辑的多边形
    for (let k = 0; k < features.length; k++) {
      this.Collection.push(features[k])
    }
    // 当编辑器存在的时候
    this.modify = new Modify({
      features: this.Collection,
      deleteCondition: function(event) {
        return shiftKeyOnly(event) && singleClick(event)
      }
    })
    this.map.addInteraction(this.modify)
    this.modify.on('modifyend', this.getEditFeature)
  }
  // 移除编辑器
  removeModify() {
    if (this.modify) {
      this.modify.un('modifyend', this.getEditFeature)
      this.map.removeInteraction(this.modify)
      this.modify = null
      this.Collection.clear()
    }
  }
  upEditData() {
    this.closeEdit()
    this.openEdit()
  }
  // 获取正在编辑的feature
  getEditFeature = (e) => {
    this.initFocusFeatures()
    this.upEditData()
    // var points = this.getFeature();
    // this.map.fire("getEditFeature", { data: points });
  }
  // 关闭编辑器
  closeEdit() {
    this.removeModify()
  }
  // +++++++++++++++++++++++end++++++++++++++++++++++++++++++++

  // ++++++++增加select选择切割后的某一块polygon++++++++++++++
  openSelect() {
    if (this.selectClick) {
      this.map.addInteraction(this.selectClick)
    }
  }
  closeSelect() {
    if (this.selectClick) {
      this.map.removeInteraction(this.selectClick)
      if ((!this.isMultiSelect) && (this.selectedFeature)) {
        this.selectedFeature.feature.setStyle(this.selectedFeature.style)
      } else if (this.selectedFeature) {
        for (let i = 0; i < this.selectedFeatures.length; i++) {
          this.selectedFeatures[i].feature.setStyle(this.selectedFeatures[i].style)
        }
      }
      this.selectedFeature = null
      this.selectedFeatures = []
    }
  }
  deleteFeature(flag) {
    if (this.selectedFeatures.length > 0) {
      for (let i = 0; i < this.selectedFeatures.length; i++) {
        this.selectedFeatures[i].feature.setStyle(this.deleteSelectedStyle)
        this.featureGroup.removeFeature(this.selectedFeatures[i].feature)
        this.deleteFocusFeature(this.selectedFeatures[i].feature)
      }
      this.selectedFeatures = []
      this.selectedFeature = null
    } else {
      if (!flag || false) {
        alert('请先至少选择一个多边形！')
      }
    }
  }
  getSelectFeatures() {
    return [].concat(this.selectedFeatures)
  }
  // 设置图层为选中
  setCommitFeatures(feature) {
    for (let i = 0; i < this.aoFocusOn.length; i++) {
      if (this.aoFocusOn[i] === feature) {
        this.aoFocusOn[i].isCommit = true
        this.aoFocusOn[i].setStyle(this.commitStyle)
        return
      }
    }
    this.aoFeatures = this.aoFocusOn
  }
  // ++++++++++++++++++++开启合并++++++++++++++++++++++++++++
  openMergePolygon() {
    this.isMergePolygon = true
    if (this.multiSelectPolygon.length < 2) {
      alert('请先至少选择两个多边形！')
      return false
    } else {
      this.MergePolygon(this.multiSelectPolygon[0], this.multiSelectPolygon[1])
    }
  }
  MergePolygon(polygon1, polygon2) {
    const geom = polygon1.getGeometry()
    const pos = geom.getCoordinates()[0]// 获取多边形的坐标点
    const geom1 = polygon2.getGeometry()
    const pos1 = geom1.getCoordinates()[0]// 获取多边形的坐标点
    for (let i = 0; i < pos.length; i++) {
      const point_web_01 = this.getLonlat(pos[i][1], pos[i][0])
      const point_01 = this.minPoint(0, point_web_01.lon, point_web_01.lat, i, polygon1)
      let point_web_02
      let point_02
      if (i + 1 < pos.length) {
        point_web_02 = this.getLonlat(pos[i + 1][1], pos[i + 1][0])
        point_02 = this.minPoint(0, point_web_02.lon, point_web_02.lat, i + 1, polygon1)
      } else {
        point_web_02 = this.getLonlat(pos[0][1], pos[0][0])
        point_02 = this.minPoint(0, point_web_02.lon, point_web_02.lat, 0, polygon1)
      }
      for (let j = 0; j < pos1.length; j++) {
        let point1_web_02
        let point1_02
        const point1_web_01 = this.getLonlat(pos1[j][1], pos1[j][0])
        const point1_01 = this.minPoint(0, point1_web_01.lon, point1_web_01.lat, j, polygon2)
        if (j + 1 < pos1.length) {
          point1_web_02 = this.getLonlat(pos1[j + 1][1], pos1[j + 1][0])
          point1_02 = this.minPoint(0, point1_web_02.lon, point1_web_02.lat, j + 1, polygon2)
        } else {
          point1_web_02 = this.getLonlat(pos1[0][1], pos1[0][0])
          point1_02 = this.minPoint(0, point1_web_02.lon, point1_web_02.lat, 0, polygon2)
        }
        // 判断是否平行
        const type = this.pdTwoLine([point_01, point_02], [point1_01, point1_02])
        if (type) {
          const isHave = this.getPublicLine([point_01, point_02], [point1_01, point1_02])
          if (isHave) { return isHave }
        }
      }
    }
    return false
  }
  getLonlat(lat, lon) {
    let point
    if (this.isWGS84) { point = TyCoordinateConvert.mercator_encrypt(lat, lon) } else { point = { lon: lon, lat: lat } }
    return point
  }
  getWGS84(lat, lon) {
    let point
    if (this.isWGS84) { point = TyCoordinateConvert.mercator_decrypt(lat, lon) } else { point = { lon: lon, lat: lat } }
    return point
  }
  closeMergePolygon() {
    this.isMergePolygon = false
  }
  // 判断两条直线是否平行且有公共部分//可以的
  pdTwoLine(line1, line2) {
    const vecter1 = [line1[1].lon - line1[0].lon, line1[1].lat - line1[0].lat]
    const vecter2 = [line2[1].lon - line2[0].lon, line2[1].lat - line2[0].lat]
    // isParallel等于0表示两线段平行，不等于0表示不平行
    const isParallel = (vecter1[0] * vecter2[1] - vecter1[1] * vecter2[0]).toFixed(3)
    // console.log(isParallel);
    if (isParallel !== 0) {
      return false
    } else {
      return true
    }
  }
  // 可以的
  isInsideLine(point, line) {
    const dLineX = line[1].lon - line[0].lon
    const dLineY = line[1].lat - line[0].lat
    const lineLength = Math.sqrt(dLineX * dLineX + dLineY * dLineY)
    const dPoint_X0 = line[1].lon - point.lon
    const dPoint_Y0 = line[1].lat - point.lat
    const dPoint_X1 = line[0].lon - point.lon
    const dPoint_Y1 = line[0].lat - point.lat
    const linePoint_length0 = Math.sqrt(dPoint_X0 * dPoint_X0 + dPoint_Y0 * dPoint_Y0)
    const linePoint_length1 = Math.sqrt(dPoint_X1 * dPoint_X1 + dPoint_Y1 * dPoint_Y1)
    if (lineLength.toFixed(3) === (linePoint_length0 + linePoint_length1).toFixed(3)) { return true } else { return false }
  }
  getPublicLine(line1, line2) {
    const type = []
    let isInside = false
    type.push(this.isInsideLine(line1[0], line2))
    type.push(this.isInsideLine(line1[1], line2))
    type.push(this.isInsideLine(line2[0], line1))
    type.push(this.isInsideLine(line2[1], line1))
    for (let i = 0; i < type.length; i++) {
      if (type[i]) {
        isInside = true
        break
      }
    }
    // 如果没有相交公共部分
    if (!isInside) {
      return false
    } else {
      // 将有公共部分的点进行排序
      const points = this.jdPX(line1, line2)
      const polygon = this.createNewPolygon(points)
      // console.log(polygon);
      if (polygon) {
        this.featureGroup.removeFeature(line1[0].Polygon)
        this.featureGroup.removeFeature(line2[0].Polygon)
        this.drawNewPolygon([[polygon, true]])
      }
      // 构建新的多边形
      return true
    }
  }
  createNewPolygon(points) {
    // console.log(points);
    let lonlats = []
    if (points[0].Polygon === points[points.length - 1].Polygon) {
      console.log('在里边')
      return false
    } else {
      console.log('交叉')
      const feature = points[points.length - 1].Polygon
      const geom = feature.getGeometry()
      const pos = geom.getCoordinates()[0]// 获取多边形的坐标点
      // var index1=points[1].Index;
      let oPoints = []

      // 下面忘记转换lon和lat
      // oPoints.push([points[2].lon, points[2].lat]);
      if (points[points.length - 1].Index === 0) {
        oPoints = oPoints.concat(pos)
      } else {
        const dd = pos.slice(points[points.length - 1].Index)
        oPoints = oPoints.concat(dd)
        const dd1 = pos.slice(0, points[1].Index)
        oPoints = oPoints.concat(dd1)// arr.reverse();逆序化
      }
      const feature1 = points[0].Polygon
      const geom1 = feature1.getGeometry()
      const pos1 = geom1.getCoordinates()[0]// 获取多边形的坐标点
      /* if (points[0].Index > points[2].Index) {

      } else {

      }*/
      if (points[2].Index === 0) {
        lonlats = pos1.concat(oPoints)
      } else {
        lonlats = pos1.slice(points[0].Index)
        lonlats = lonlats.concat(oPoints)
        const dd3 = pos1.slice(0, points[2].Index + 1)
        lonlats = lonlats.concat(dd3)
      }
      // lonlats=oPoints;
      return lonlats
    }
  }
  // 如果有交点就进行排序,//可以的
  jdPX(line1, line2) {
    let outside = null
    const dd = [
      [line1[0], [line1[1], line2[0], line2[1]]],
      [line1[1], [line1[0], line2[0], line2[1]]],
      [line2[0], [line2[1], line1[0], line2[1]]],
      [line2[1], [line2[0], line1[0], line2[1]]]
    ]
    // 求出一个最左或最右的点
    for (let j = 0; j < dd.length; j++) {
      if (this.isOutSide(dd[j][0], dd[j][1])) {
        // 全部同向取出这个点
        outside = dd[j]
        break
      }
    }
    const startPoint = outside[0]
    outside[1].push(startPoint)
    for (let i = 0; i < outside[1].length; i++) {
      outside[1][i].Distance = this.getPointsDistance(outside[0], outside[1][i])
    }
    for (let k = 0, v = outside[1].length; k < v; k++) {
      for (let t = 0; t < v - k; t++) {
        if (t + 1 < v - k) {
          if (outside[1][t].Distance > outside[1][t + 1].Distance) {
            const data = outside[1][t]
            outside[1][t] = outside[1][t + 1]
            outside[1][t + 1] = data
          }
        }
      }
    }
    return outside[1]
  }
  // 通过求解一点与其他点构成的向量是否都是同向来判断是否处于最外边
  isOutSide(point, points) {
    const vecters = []
    for (let i = 0; i < points.length; i++) {
      const vecter = [point.lon - points[i].lon, point.lat - points[i].lat]
      vecters.push(vecter)
    }
    const test = vecters[0]
    for (let j = 1; j < vecters.length; j++) {
      if ((vecters[j][0] * test[0] - vecters[j][1] * test[1]) < 0) { return false }
    }
    return true
  }
  // +++++++++++++++++++++++++++++++++++++++++++++++++++
  // +++++++++++++++++开启多选和关闭多选++++++++++++++++++++++++++
  openMultiSelect() {
    this.isMultiSelect = true
  }
  closeMultiSelect() {
    this.isMultiSelect = false
    for (let i = 0; i < this.selectedFeatures.length; i++) {
      this.selectedFeatures[i].feature.setStyle(this.selectedFeatures[i].style)
    }
    if (this.selectedFeature) {
      this.selectedFeature.feature.setStyle(this.selectedFeature.style)
    }
    this.selectedFeatures = []
    this.selectedFeature = null
  }
  // +++++++++++++++++++++++++++++++++++++++
  initFocusFeatures() {
    this.aoFocusOn = this.aoFeatures
  }

  addPolygon(aoPolygon) {
    this.featureGroup.addFeature(aoPolygon)
    this.aoFeatures.push(aoPolygon)
  }

  setDrawToolStyle(color) {
    const oStyle = new Style({
      fill: new Fill({
        color: color
      }),
      stroke: new Stroke({
        color: '#ffcc33',
        width: 3
      }),
      image: new CircleStyle({
        radius: 7,
        fill: new Fill({
          color: '#ffcc33'
        })
      })
    })
    if (this.drawTool) {
      this.drawTool.setStyle(oStyle)
    }
    return oStyle
  }

  initTool() { // 初始化绘图工具
    // 选择样式
    this.selectedStyle = new Style({
      stroke: new Stroke({
        color: [100, 255, 255, 1],
        width: 5
      }),
      fill: new Fill({
        color: [255, 255, 255, 0.5]
      })
    })
    // 取消选择样式
    this.unSelectedStyle = new Style({
      stroke: new Stroke({
        color: [250, 100, 20, 1],
        width: 1
      }),
      fill: new Fill({
        color: [250, 100, 20, 0.4]
      })
    })
    // 删除样式 透明
    this.deleteSelectedStyle = new Style({
      stroke: new Stroke({
        color: [255, 255, 255, 0]
      }),
      fill: new Fill({
        color: [255, 255, 255, 0]
      })
    })

    // 提交样式
    this.commitStyle = new Style({
      stroke: new Stroke({
        color: 'rgba(250,100,20,1)',
        width: 1
      }),
      fill: new Fill({
        color: 'rgba(0, 200, 0, 0.6)'
      }),
      text: new Text({
        textAlign: 'center',
        textBaseline: 'bottom',
        font: '3 12px Arial',
        text: '已提交！',
        fill: new Fill({ color: '#aa3300' }), // 字体填充色
        stroke: new Stroke({ color: '#ffffff', width: 3 }), // 字体的外边界
        offsetX: 0,
        offsetY: 0,
        rotation: 0
      })
    })

    // 切割线样式
    this.drawTool = new TyDrawTool(this.map, new Style({
      fill: new Fill({
        color: 'rgba(255, 255, 255, 0.2)'
      }),
      stroke: new Stroke({
        color: '#ffcc33',
        width: 3
      }),
      image: new CircleStyle({
        radius: 7,
        fill: new Fill({
          color: '#ffcc33'
        })
      })
    }))
    this.selectClick = new Select({
      condition: click
      // addCondition: click
      // condition: ol.events.condition.pointerMove
    })
    this.selectClick.on('select', (e) => {
      this.setSelectFeatures(e.selected)
    })
  }

  setSelectFeatures(features) {
    if (features.length !== 0) {
      if (this.isMultiSelect) {
        let flag = true
        this.selectedFeatures.forEach((item) => {
          if (item.feature === features[0]) {
            flag = false
            return
          }
        })
        if (flag) {
          this.selectedFeatures.push({ feature: features[0], style: features[0].getStyle() })
          this.selectedFeature = { feature: features[0], style: features[0].getStyle() }
          features[0].setStyle(this.selectedStyle)
        }
      } else {
        if (this.selectedFeature) {
          this.selectedFeature.feature.setStyle(this.selectedFeature.style)
        }
        this.selectedFeatures = [{ feature: features[0], style: features[0].getStyle() }]
        this.selectedFeature = { feature: features[0], style: features[0].getStyle() }
        features[0].setStyle(this.selectedStyle)
      }
    } else {
      this.selectedFeatures.forEach((item) => {
        item.feature.setStyle(this.selectedFeature.style)
      })
      this.selectedFeatures = []
      this.selectedFeature = null
    }
  }
  getAllFeature() {
    return this.aoFocusOn
  }
  // 切割
  cute() {
    if (this.drawTool) {
      this.drawTool.start('LineString', (event) => {
        let polygons
        const feature = event.feature
        const geom = feature.getGeometry()
        const pos = geom.getCoordinates()// 获取多边形的坐标点
        if (this.aoFocusOn.length !== 0) {
          for (let i = 0; i < this.aoFocusOn.length; i++) {
            polygons = this.cutePolygon(this.aoFocusOn[i], pos)
            if (polygons && (polygons.length !== 0)) {
              this.aoDeletePolygon.push(this.aoFocusOn[i])
              this.drawNewPolygon(polygons)
            }
          }
          this.removeOldFeature()
        }
        setTimeout(() => {
          this.drawTool.clear()
        }, 100)
      })
    }
  }
  closeCute() {
    if (this.drawTool) { this.drawTool.close() }
  }
  removeOldFeature() {
    const oldFeatures = []
    for (let i = 0; i < this.aoDeletePolygon.length; i++) {
      this.featureGroup.removeFeature(this.aoDeletePolygon[i])
      for (let j = this.aoFocusOn.length; j >= 0; j--) {
        if (this.aoFocusOn[j] === this.aoDeletePolygon[i]) {
          oldFeatures.push(this.aoFocusOn[j])
          this.aoFocusOn.splice(j, 1)
        }
      }
    }
    const newFeatures = [].concat(this.aoCreatePolygon)
    this.aoFocusOn = this.aoFocusOn.concat(this.aoCreatePolygon)
    this.aoLastStep.push([oldFeatures, newFeatures])
    this.aoFeatures = this.aoFocusOn
    this.aoDeletePolygon = []
    this.aoCreatePolygon = []
  }
  drawNewPolygon(polygons) {
    /* const style = new Style({
      stroke: new Stroke({
        color: 'rgba(250,100,20,1)',
        width: 10
      }),
      fill: new Fill({
        color: 'rgba(250,100,20,0.4)'
      })
    })*/
    for (let i = 0; i < polygons.length; i++) {
      if (polygons[i][1]) {
        const geom = new Polygon([polygons[i][0]])
        const feature = new Feature({
          geometry: geom
        })
        // feature.setStyle(style)
        this.featureGroup.addFeature(feature)
        this.aoCreatePolygon.push(feature)
      }
    }
  }
  cutePolygon(polygon, line) {
    const geom = polygon.getGeometry()
    const pos = geom.getCoordinates()[0]// 获取多边形的坐标点
    const lonlats = this.wgsToWebM(pos)
    let jds = []
    for (let i = 0; i < pos.length; i++) {
      let point1
      let point2
      if (i + 1 < pos.length) {
        point1 = this.getLonlat(pos[i][1], pos[i][0])
        point2 = this.getLonlat(pos[i + 1][1], pos[i + 1][0])
      } else {
        point1 = this.getLonlat(pos[i][1], pos[i][0])
        point2 = this.getLonlat(pos[0][1], pos[0][0])
      }
      const dd = this.allLineSegmentsIntr([point1.lon, point1.lat], [point2.lon, point2.lat], line, polygon, i)
      if (dd) {
        jds = jds.concat(dd)
      }
    }
    for (let j = 0; j < jds.length; j++) {
      const point = this.getWGS84(jds[j].lat, jds[j].lon)
      jds[j].lon = point.lon
      jds[j].lat = point.lat
    }
    if (jds.length < 2) { return false }
    const points = this.sortData(jds[0], jds)
    // console.log(points);
    const polygons = this.createCutePolygon(points, lonlats, line)
    for (let k = 0; k < polygons.length; k++) {
      polygons[k][0] = this.WebMToWGS(polygons[k][0])
    }
    return polygons
  }
  allLineSegmentsIntr(a, b, line, polygon, index) {
    const jdPoints = []
    for (let i = 0; i < line.length; i++) {
      if (i + 1 < line.length) {
        const point1 = this.getLonlat(line[i][1], line[i][0])
        const point2 = this.getLonlat(line[i + 1][1], line[i + 1][0])
        const jd = this.segmentsIntr(a, b, [point1.lon, point1.lat], [point2.lon, point2.lat])
        if (jd) {
          jdPoints.push(this.minPoint(0, jd[0], jd[1], index, polygon, i))
        }
      }
    }
    return jdPoints
  }
  // 求解两个线段的交点
  segmentsIntr(a, b, c, d) {
    const denominator = (b[1] - a[1]) * (d[0] - c[0]) - (a[0] - b[0]) * (c[1] - d[1])
    if (denominator === 0) {
      if (((a[0] === c[0]) && (a[1] === c[1])) || ((a[0] === d[0]) && (a[1] === d[1]))) {
        return [c, d]
      }
    }
    const x = ((b[0] - a[0]) * (d[0] - c[0]) * (c[1] - a[1]) +
      (b[1] - a[1]) * (d[0] - c[0]) * a[0] -
      (d[1] - c[1]) * (b[0] - a[0]) * c[0]) / denominator
    const y = -((b[1] - a[1]) * (d[1] - c[1]) * (c[0] - a[0]) +
      (b[0] - a[0]) * (d[1] - c[1]) * a[1] -
      (d[0] - c[0]) * (b[1] - a[1]) * c[1]) / denominator
    if (
      (x - a[0]) * (x - b[0]) <= 0 && (y - a[1]) * (y - b[1]) <= 0 &&
      (x - c[0]) * (x - d[0]) <= 0 && (y - c[1]) * (y - d[1]) <= 0
    ) {
      return [parseFloat(x.toFixed(6)), parseFloat(y.toFixed(6))]
    }
    return false
  }

  wgsToWebM(wPoints) {
    const mPoints = []
    for (let i = 0; i < wPoints.length; i++) {
      const point = this.getLonlat(wPoints[i][1], wPoints[i][0])
      mPoints.push(point)
    }
    return mPoints
  }
  WebMToWGS(wPoints) {
    const mPoints = []
    for (let i = 0; i < wPoints.length; i++) {
      const point = this.getWGS84(wPoints[i][0], wPoints[i][1])
      mPoints.push([point.lon, point.lat])
    }
    return mPoints
  }
  // 给交点排序，按照线段的顺序进行
  sortData(pointA, intersectData) {
    for (let i = 0; i < intersectData.length; i++) {
      const point = this.getLonlat(intersectData[i].lat, intersectData[i].lon)
      intersectData[i].lon = point.lon
      intersectData[i].lat = point.lat
      intersectData[i].Distance = this.getPointsDistance(pointA, intersectData[i])
    }
    for (let k = 0, j = intersectData.length; k < j; k++) {
      for (let t = 0; t < j - k; t++) {
        if (t + 1 < j - k) {
          if (intersectData[t].Distance > intersectData[t + 1].Distance) {
            const data = intersectData[t]
            intersectData[t] = intersectData[t + 1]
            intersectData[t + 1] = data
          }
        }
      }
    }
    // for(var k= 0,j=intersectData.length;k<j;k++){
    //    for(var t=0;t<j-k;t++){
    //        if(t+1<j-k){
    //            if(intersectData[t].lineIndex>intersectData[t+1].lineIndex){
    //                var data=intersectData[t];
    //                intersectData[t]=intersectData[t+1];
    //                intersectData[t+1]=data;
    //            }
    //        }
    //    }
    // }

    return intersectData
  }

  getPointsDistance(point1, point2) {
    return Math.sqrt((point1.lon - point2.lon) * (point1.lon - point2.lon) + (point1.lat - point2.lat) * (point1.lat - point2.lat))
  }

  // aoData是排序后的交点，lonlats是多边形的坐标点，功能：判断交点的中点是否处于多边形内，以此判断是否切割多边形
  getUsedData(aoData, lonlats, line) {
    const points = []
    const nvertx = []
    const nverty = []
    const nvert = lonlats.length
    for (let j = 0; j < nvert; j++) {
      nvertx.push(lonlats[j].lat)
      nverty.push(lonlats[j].lon)
    }
    for (let i = 0; i < aoData.length; i++) {
      if (i < aoData.length - 1) {
        if ((aoData[i + 1].lat !== aoData[i].lat) && (aoData[i + 1].lon !== aoData[i].lon)) {
          let centerPoint
          let point
          if (aoData[i].Index !== aoData[i + 1].Index) {
            if (aoData[i].lineIndex !== aoData[i + 1].lineIndex) {
              if (aoData[i].lineIndex < aoData[i + 1].lineIndex) {
                point = this.getLonlat(line[aoData[i].lineIndex + 1][1], line[aoData[i].lineIndex + 1][0])
              } else {
                point = this.getLonlat(line[aoData[i + 1].lineIndex + 1][1], line[aoData[i + 1].lineIndex + 1][0])
              }
              centerPoint = [point.lat, point.lon]
            } else {
              centerPoint = [(aoData[i + 1].lat + aoData[i].lat) / 2, (aoData[i + 1].lon + aoData[i].lon) / 2]
            }
          } else {
            const points1 = this.getLinePoint(aoData[i].lineIndex, aoData[i + 1].lineIndex, line)
            centerPoint = points1[0]
          }
          // console.log([aoData[i],aoData[i+1]]);
          // 这儿有问题，原先直线是求中心点，现在可能不为直线，
          // 如果绕一个凸角不相交的话，求两相邻交点中点是否在多边形内是错位的
          const isIn = this.inPolygon(nvert, nvertx, nverty, centerPoint[0], centerPoint[1])
          if (isIn) {
            points.push([aoData[i], aoData[i + 1], true])
            this.isHasIn = true
          } else {
            points.push([aoData[i], aoData[i + 1], false])
          }
        }
      }
    }
    return points
  }

  // 判断点是否处于多边形内
  inPolygon(nvert, vertx, verty, testx, testy) {
    let c = 0
    for (let i = 0, j = nvert - 1; i < nvert; j = i++) {
      if (((verty[i] > testy) !== (verty[j] > testy)) &&
        (testx < (vertx[j] - vertx[i]) * (testy - verty[i]) / (verty[j] - verty[i]) + vertx[i])) { c = !c }
    }
    return c
  }

  // 判断是否处于首尾交点内
  hasMidIndex(myIntersect, startIndex, endIndex) {
    for (let v = 0; v < myIntersect.length; v++) {
      if ((myIntersect[v][0].Index > startIndex && myIntersect[v][0].Index < endIndex) ||
        ((myIntersect[v][1].Index > startIndex && myIntersect[v][1].Index < endIndex))) {
        return true
      }
    }
    return false
  }

  // 获取每一部分的多边形坐标，这个函数是在中间相邻交点构成切割情况下使用
  getNewPolygon(pointArray, myIntersect, headPoint, endPoint, FirstIndex, LastIndex, hasMid, line) {
    const startIndex = Math.min(myIntersect[0].Index, myIntersect[1].Index)
    const endIndex = Math.max(myIntersect[0].Index, myIntersect[1].Index)
    let startLineIndex
    let endLineIndex
    if (myIntersect[0].Index === startIndex) {
      startLineIndex = myIntersect[0].lineIndex
      endLineIndex = myIntersect[1].lineIndex
    } else {
      startLineIndex = myIntersect[1].lineIndex
      endLineIndex = myIntersect[0].lineIndex
    }
    const linePoint = this.getLinePoint(startLineIndex, endLineIndex, line)
    let newLatlng = []
    if (myIntersect[0].Index !== myIntersect[1].Index) {
      for (let j = 0; j < pointArray.length; j++) {
        // 被切割部分
        if (hasMid) {
          if (j < (startIndex + 1) || j > endIndex) {
            newLatlng.push([pointArray[j].lat, pointArray[j].lon])
          }
          if (j === pointArray.length - 1) {
            newLatlng.splice(FirstIndex + 1, 0, [headPoint.lat, headPoint.lon])
            for (let k = 0; k < linePoint.length; k++) {
              newLatlng.splice(FirstIndex + 2 + k, 0, linePoint[k])
            }
            newLatlng.splice(FirstIndex + 2 + linePoint.length, 0, [endPoint.lat, endPoint.lon])
          }
        } else { // 不被切割部分，为不是相邻两点切割获取坐标做准备
          if (j === 0) { newLatlng.push([headPoint.lat, headPoint.lon]) }
          if ((j > startIndex) && (j < endIndex + 1)) {
            newLatlng.push([pointArray[j].lat, pointArray[j].lon])
          }
          if (j === pointArray.length - 1) {
            newLatlng.push([endPoint.lat, endPoint.lon])
            newLatlng = newLatlng.concat(linePoint.reverse())
          }
        }
      }
    } else {
      // console.log("这儿共边了！");
      // console.log(myIntersect[2]);
    }
    if (myIntersect[2]) {
      return [newLatlng, true]
    } else {
      return [newLatlng, false]
    }
  }

  // 寻找两个交点之间的line节点信息
  getLinePoint(startLineIndex, endLineIndex, line) {
    let startIndex
    let endIndex
    let points = []
    let isN = false
    if (startLineIndex >= endLineIndex) {
      isN = true
      startIndex = endLineIndex
      endIndex = startLineIndex
    } else {
      startIndex = startLineIndex
      endIndex = endLineIndex
    }
    const dd = line.slice(startIndex + 1, endIndex + 1)
    points = points.concat(dd)
    if (isN) { points = points.reverse() }
    for (let i = 0; i < points.length; i++) {
      const point = this.getLonlat(points[i][1], points[i][0])
      points[i] = [point.lat, point.lon]
    }
    return points
  }

  // 判断绘制切割线与多边形方向是否一致
  getDirection(startPoint, endPoint, lonlats) {
    const index = startPoint.Index
    const point = lonlats[index]
    // console.log(point);
    const distance1 = this.getPointsDistance(startPoint, point)
    const distance2 = this.getPointsDistance(endPoint, point)
    if (distance1 < distance2) {
      return true
    } else {
      return false
    }
  }
  // 更新起始点个终点
  getStartAndEnd(points, lonlats, select) {
    const endIndex = points.length - 1
    const startNode = []
    const endNode = []
    let FirstIndex
    let LastIndex
    let lineStartIndex
    let lineEndIndex
    if (select) {
      startNode.push(points[endIndex].lat, points[endIndex].lon)
      endNode.push(points[0].lat, points[0].lon)
      FirstIndex = points[endIndex].Index
      LastIndex = points[0].Index
      lineStartIndex = points[endIndex].lineIndex
      lineEndIndex = points[0].lineIndex
    } else {
      endNode.push(points[endIndex].lat, points[endIndex].lon)
      startNode.push(points[0].lat, points[0].lon)
      LastIndex = points[endIndex].Index
      FirstIndex = points[0].Index
      lineStartIndex = points[0].lineIndex
      lineEndIndex = points[endIndex].lineIndex
    }
    return {
      startNode: startNode,
      endNode: endNode,
      FirstIndex: FirstIndex,
      LastIndex: LastIndex,
      lineStartIndex: lineStartIndex,
      lineEndIndex: lineEndIndex
    }
  }
  // 生成多边形
  createCutePolygon(points, lonlats, line) {
    const end_Index = points.length - 1
    let select
    const isSXZ = this.getDirection(points[end_Index], points[0], lonlats)
    if (points[end_Index].Index < points[0].Index) { // ||(isSXZ)) {
      select = true
    } else if (points[end_Index].Index > points[0].Index) {
      select = false
    } else {
      if (isSXZ) { select = true } else { select = false }
    }
    const data = this.getStartAndEnd(points, lonlats, select)
    const startNode = data.startNode
    const endNode = data.endNode
    const FirstIndex = data.FirstIndex
    const LastIndex = data.LastIndex
    const lineStartIndex = data.lineStartIndex
    const lineEndIndex = data.lineEndIndex
    if ((FirstIndex === LastIndex) && (line.length === 2)) {
      alert('切割线不能共边！')
      return false
    }
    const myIntersect = this.getUsedData(points, lonlats, line)
    // console.log(myIntersect);
    const pointArray = lonlats
    const lonlat = []
    if (this.isHasIn) {
      // +++++++++中间相邻交代切割部分+++++++++++++++++++
      if (points.length === 2) {
        let dd = this.getLinePoint(lineStartIndex, lineEndIndex, line)
        // +++++++用来判断当只有两点交点时判断是否切割++++++++++
        if (points[0].lineIndex !== points[1].lineIndex) {
          const nvertx = []
          const nverty = []
          const nvert = lonlats.length
          for (let j = 0; j < nvert; j++) {
            nvertx.push(lonlats[j].lat)
            nverty.push(lonlats[j].lon)
          }
          const centerPoint = dd[0]
          const isIn = this.inPolygon(nvert, nvertx, nverty, centerPoint[0], centerPoint[1])
          if (!isIn) { return false }
        }
        // +++++++++++++++++++++++++++++++
        const FirstLnglats = []
        let LastLnglats = []
        LastLnglats.push(startNode)
        for (let i = 0; i < pointArray.length; i++) {
          if (i > FirstIndex && i < LastIndex + 1) {
            LastLnglats.push([pointArray[i].lat, pointArray[i].lon])
          } else {
            FirstLnglats.push([pointArray[i].lat, pointArray[i].lon])
          }
        }
        LastLnglats.push(endNode)
        LastLnglats = LastLnglats.concat(dd.reverse())
        FirstLnglats.splice(FirstIndex + 1, 0, startNode)
        dd = dd.reverse()
        for (let ii = 0; ii < dd.length; ii++) {
          FirstLnglats.splice(FirstIndex + 1 + ii + 1, 0, dd[ii])
        }
        FirstLnglats.splice(FirstIndex + 2 + dd.length, 0, endNode)
        lonlat.push([LastLnglats, true], [FirstLnglats, true])
        // console.log(lonlat);
      } else {
        // 返回的有效切割线段如：ab交多边形a->c->d->b,返回ac,cd,db,每个线段都有属性false/true判断是否为有效切割
        for (let v = 0; v < myIntersect.length; v++) {
          let headPoint
          let endPoint
          // 给ac的a和c端点进行索引排序，从小往大
          if (myIntersect[v][0].Index > myIntersect[v][1].Index) {
            headPoint = myIntersect[v][1]
            endPoint = myIntersect[v][0]
          } else {
            headPoint = myIntersect[v][0]
            endPoint = myIntersect[v][1]
          }
          const startIndex = Math.min(myIntersect[v][0].Index, myIntersect[v][1].Index)
          const endIndex = Math.max(myIntersect[v][0].Index, myIntersect[v][1].Index)
          const hasMid = this.hasMidIndex(myIntersect, startIndex, endIndex)
          lonlat.push(this.getNewPolygon(pointArray, myIntersect[v], headPoint, endPoint, FirstIndex, LastIndex, hasMid, line))
          // console.log(this.getNewPolygon(pointArray,myIntersect[v],headPoint,endPoint,FirstIndex,LastIndex,hasMid,line));
        }
        // +++++++++++++++++++++++++++++++++++++++end+++++++++++++++++++++++++++++++++++++++++

        // +++++++++++++++++++++++++++++++++++++++首尾切割部分：第一个是确定首位之间的原多边形部分，第二是相邻点切割部分的坐标计算+++++++++++++++++++++++++++++++++++++++++
        let points0 = []
        if (!this.hasMidIndex(myIntersect, FirstIndex, LastIndex)) { // 包括起始点
          for (let w = myIntersect.length - 1; w >= 0; w--) {
            let headPoint0
            let endPoint0
            let startLineIndex
            let endLineIndex
            const startIndex0 = Math.min(myIntersect[w][0].Index, myIntersect[w][1].Index)
            const endIndex0 = Math.max(myIntersect[w][0].Index, myIntersect[w][1].Index)
            if (myIntersect[w][0].Index === startIndex0) {
              startLineIndex = myIntersect[w][0].lineIndex
              endLineIndex = myIntersect[w][1].lineIndex
            } else {
              startLineIndex = myIntersect[w][1].lineIndex
              endLineIndex = myIntersect[w][0].lineIndex
            }
            let linePoint = this.getLinePoint(startLineIndex, endLineIndex, line)
            if (!this.hasMidIndex(myIntersect, startIndex0, endIndex0)) {
              if (myIntersect[w][0].Index > myIntersect[w][1].Index) {
                headPoint0 = myIntersect[w][1]
                endPoint0 = myIntersect[w][0]
              } else {
                headPoint0 = myIntersect[w][0]
                endPoint0 = myIntersect[w][1]
              }
            } else {
              headPoint0 = myIntersect[w][1]
              endPoint0 = myIntersect[w][0]
            }
            // 判断是否为切割部分
            if (lonlat[w][1]) {
              points0.push([headPoint0.lat, headPoint0.lon])
              if (w === 0) {
                linePoint = linePoint.reverse()
              }
              points0 = points0.concat(linePoint)
              points0.push([endPoint0.lat, endPoint0.lon])
            } else {
              for (let tt = 0; tt < lonlat[w][0].length; tt++) {
                if (this.searchLinePoint([lonlat[w][0][tt][0], lonlat[w][0][tt][1]], points)) {
                  points0.push([lonlat[w][0][tt][0], lonlat[w][0][tt][1]])
                } else {
                  if (this.searchPolygonPoint([lonlat[w][0][tt][0], lonlat[w][0][tt][1]], lonlats)) {
                    points0.push([lonlat[w][0][tt][0], lonlat[w][0][tt][1]])
                  }
                }
              }
            }
          }
        } else { // 不包括起始点
          for (let w0 = myIntersect.length - 1; w0 >= 0; w0--) {
            let headPoint1
            let endPoint1
            let startLineIndex1
            let endLineIndex1
            const startIndex1 = Math.min(myIntersect[w0][0].Index, myIntersect[w0][1].Index)
            const endIndex1 = Math.max(myIntersect[w0][0].Index, myIntersect[w0][1].Index)
            if (myIntersect[w0][0].Index === startIndex1) {
              startLineIndex1 = myIntersect[w0][0].lineIndex
              endLineIndex1 = myIntersect[w0][1].lineIndex
            } else {
              startLineIndex1 = myIntersect[w0][1].lineIndex
              endLineIndex1 = myIntersect[w0][0].lineIndex
            }
            let linePoint1 = this.getLinePoint(startLineIndex1, endLineIndex1, line)
            if (!this.hasMidIndex(myIntersect, startIndex1, endIndex1)) {
              headPoint1 = myIntersect[w0][1]
              endPoint1 = myIntersect[w0][0]
            } else {
              headPoint1 = myIntersect[w0][0]
              endPoint1 = myIntersect[w0][1]
            }
            // 判断是否为切割部分
            if (lonlat[w0][1]) {
              linePoint1 = linePoint1.reverse()
              points0.push([headPoint1.lat, headPoint1.lon])
              points0 = points0.concat(linePoint1)
              points0.push([endPoint1.lat, endPoint1.lon])
            } else {
              for (let tt0 = lonlat[w0][0].length - 1; tt0 >= 0; tt0--) {
                if (this.searchLinePoint([lonlat[w0][0][tt0][0], lonlat[w0][0][tt0][1]], points)) {
                  points0.push([lonlat[w0][0][tt0][0], lonlat[w0][0][tt0][1]])
                } else {
                  if (this.searchPolygonPoint([lonlat[w0][0][tt0][0], lonlat[w0][0][tt0][1]], lonlats)) {
                    points0.push([lonlat[w0][0][tt0][0], lonlat[w0][0][tt0][1]])
                  }
                }
              }
            }
          }
        }
        // 下面没问题

        const mypoints = points0.slice(0)// 数组克隆
        // +++++++++++++++++++++
        const LastLnglats0 = []
        const lastLnglats = []
        const hasMid0 = this.hasMidIndex(myIntersect, FirstIndex, LastIndex)
        if (!hasMid0) {
          // console.log("不包括起点！");
          for (let i0 = 0; i0 < pointArray.length; i0++) {
            if (i0 > FirstIndex && i0 < LastIndex + 1) {
              LastLnglats0.push([pointArray[i0].lat, pointArray[i0].lon])
            }
          }
          for (let jj = 0; jj < mypoints.length; jj++) {
            LastLnglats0.push(mypoints[jj])
          }
        } else {
          // console.log("包括起点！");
          for (let i1 = 0; i1 < pointArray.length; i1++) {
            if (i1 < FirstIndex + 1) {
              LastLnglats0.push([pointArray[i1].lat, pointArray[i1].lon])
            }
            if (i1 > LastIndex) {
              lastLnglats.push([pointArray[i1].lat, pointArray[i1].lon])
            }
          }
          for (let jj0 = mypoints.length - 1; jj0 >= 0; jj0--) {
            LastLnglats0.push(mypoints[jj0])
          }
          for (let r = 0; r < lastLnglats.length; r++) {
            LastLnglats0.push(lastLnglats[r])
          }
        }
        lonlat.push([LastLnglats0, true])
      }
    }
    // +++++++++++++++++++++++++++++++++++++++end+++++++++++++++++++++++++++++++++++++++++
    return lonlat
  }
  // 查找该点是否属于交点
  searchLinePoint(point, points) {
    for (let i = 0; i < points.length; i++) {
      if (points[i].lon) {
        if ((point[0] === points[i].lon) && (point[1] === points[i].lat)) {
          return true
        }
      }
    }
    return false
  }
  searchPolygonPoint(point, points) {
    for (let i = 0; i < points.length; i++) {
      if (points[i].lon) {
        if ((point[0] === points[i].lat) && (point[1] === points[i].lon)) {
          return true
        }
      }
    }
    return false
  }
  /* getNewPolygon(obj1) {
    const account_index = []
    const S_Index = obj1.length
    const data11
    tt11(obj1)
    return data11
    function tt11(obj) {
      if (obj.length === 1) {
        const ttu = []
        const ghj = obj[0]
        for (let kl1 = 0; kl1 < obj[0].length; kl1++) {
          ttu.push(ghj[kl1])
        }
        data11 = ttu
      } else {
        var N_nears = []// 存储最左坐标数据
        var J_index = []// 存储每个岛的最左坐标的index和岛在所有岛的index
        for (var i = 1; i < obj.length; i++) { // 0为外环
          var d_polygon = obj[i]
          var polygon_point_index = []
          polygon_point_index.push(i)
          var left_point = d_polygon[0]
          var left_index = 0
          for (var j = 1; j < d_polygon.length; j++) {
            var this_polygon = d_polygon[j]
            if (this_polygon[0] <= left_point[0]) {
              left_point = d_polygon[j]
              left_index = j
            }
          }
          N_nears.push(left_point)
          polygon_point_index.push(left_index)
          J_index.push(polygon_point_index)
        }
        // 查找每个岛最左的最小值
        var N_near = N_nears[0]
        var jl_index = J_index[0]
        for (var k = 1; k < N_nears.length; k++) {
          var kk = N_nears[k]
          var kl = J_index[k]
          if (kk[0] <= N_near[0]) {
            N_near = kk
            jl_index = kl
          }
        }
        account_index.push(jl_index[0])
        // 生成新的要插入的数组
        var new_points = []
        var gg = obj[jl_index[0]]
        var dp = gg.length
        if (jl_index[1] == 0 || jl_index[1] == (dp - 1)) {
          for (var r = 0; r < dp; r++) {
            new_points.push(gg[r])
          }
        } else {
          for (var rr = jl_index[1]; rr < dp; rr++) {
            new_points.push(gg[rr])
          }
          for (var rrr = 1; rrr < jl_index[1] + 1; rrr++) {
            new_points.push(gg[rrr])
          }
        }
        // 计算最左值与在它左边的外环顶点的距离
        var hh = obj[0]
        var distances2 = []
        var polygon_w_indexs = []
        for (var l = 0; l < hh.length; l++) {
          var hhh = hh[l]
          if (hhh[0] <= N_near[0]) {
            var ds = Math.sqrt((hhh[0] - N_near[0]) * (hhh[0] - N_near[0]) + (hhh[1] - N_near[1]) * (hhh[1] - N_near[1]))
            distances2.push(ds)
            polygon_w_indexs.push(l)
          }
        }
        var distance1 = distances2[0]
        var polygon_w_index = polygon_w_indexs[0]
        for (var t = 1; t < distances2.length; t++) {
          if (distances2[t] <= distance1) {
            distance1 = distances2[t]
            polygon_w_index = polygon_w_indexs[t]
          }
        }
        var new_obj = hh
        var index11
        for (var tt = 0; tt < new_points.length; tt++) {
          new_obj.splice((polygon_w_index + tt + 1), 0, new_points[tt])
          index11 = (polygon_w_index + tt + 1)
        }
        new_obj.splice(index11 + 1, 0, hh[polygon_w_index])

        if (account_index.length == (S_Index - 1)) {
          data11 = new_obj
        } else {
          var data = []
          data.push(new_obj)
          for (var i1 = 1; i1 < obj.length; i1++) {
            var t1 = 0
            if (i1 != jl_index[0]) {
              data.push(obj[i1])
            }
          }
          tt11(data)
        }
      }
    }
  },*/
  getRingPolygon(features, outSideIsDel, islandIsDel) {
    if (features.length === 0) {
      return
    }
    const outSideFeature = features[0].feature
    const pos = outSideFeature.getGeometry().getCoordinates()
    // const polygonPoints = []
    for (let i = 1; i < features.length; i++) {
      pos.push(features[i].feature.getGeometry().getCoordinates()[0])
      if (islandIsDel) {
        this.deleteFocusFeature(features[i].feature)
        this.featureGroup.removeFeature(features[i].feature)
      }
    }
    const geom = new Polygon(pos)
    const feature = new Feature({
      geometry: geom
    })
    this.addPolygon(feature)
    this.initFocusFeatures()
    if (outSideIsDel) {
      this.deleteFocusFeature(features[0].feature)
      this.featureGroup.removeFeature(features[0].feature)
    }
    return feature
  }
  getMultiPolygon(features) {
    if (features.length < 2) { return null }
    const polygonPoints = []
    for (let i = 0; i < features.length; i++) {
      polygonPoints.push(features[i].feature.getGeometry().getCoordinates())
      this.deleteFocusFeature(features[i].feature)
      this.featureGroup.removeFeature(features[i].feature)
    }
    const geom = new MultiPolygon(polygonPoints)
    const feature = new Feature({
      geometry: geom
    })
    this.addPolygon(feature)
    this.initFocusFeatures()
    return feature
  }

  minPoint(distance, lon, lat, index, polygon, index1) {
    return {
      Distance: distance, // 绑定点的距离属性，特定时刻的需求
      lon: lon, // 维度
      lat: lat, // 经度
      Index: index, // 该点在多边形内的索引
      lineIndex: index1, // 该点在切割线的索引
      Polygon: polygon// 被切割的多边形
    }
  }
}
export default TyDrawPolygon
